<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListTecnicoTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">

            <p:growl id="messages" life="3000"/>

            <h:panelGroup id="messagePanel" styleClass="ajustaListaMensagemErro"  layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="list"/>
            </h:panelGroup>

            <h:panelGroup >
                <p:dataTable id="tbl" value="#{tecnicoController.lista}" var="item"  paginator="true" rows="#{bundle.rows10}" widgetVar="tecnicosTable"  
                             currentPageReportTemplate="#{bundle.currentPageReportTemplateTecnico}" pageLinks="5"  paginatorTemplate="#{bundle.paginatorTemplate}"
                             rowsPerPageTemplate="#{bundle.rowsPerPageTemplate}"   paginatorPosition="#{bundle.paginatorPosition}" emptyMessage="#{bundle.ListTecnicoEmpty}" 
                             rowKey="#{item.tecId}" selection="#{tecnicoController.selectedTecnico}" selectionMode="single" filteredValue="#{tecnicoController.lista}"
                             styleClass="mystyle" binding="#{tecnicoController.tabela}">                       

                    <f:facet id="global" name="header">
                        <p:outputPanel id="test" >
                            <h:outputText value="#{bundle.searchAllFields}" />
                            <p:inputText id="globalFilter" onkeyup="tecnicosTable.filter();" style="width: 200px;" >
                                <p:focus for="globalFilter" />
                            </p:inputText>
                        </p:outputPanel>
                    </f:facet>

                    <p:column  styleClass="firstColumn"  filterBy="#{item.tecId}" sortBy="#{item.tecId}" >
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecId}"/>
                        </f:facet>
                        <h:outputText value="#{item.tecId}"/>  
                    </p:column>

                    <p:column sortBy="#{item.tecNm}#{filterSearchController.removeAcentos(item.tecNm)}" 
                              filterBy="#{item.tecNm}#{filterSearchController.removeAcentos(item.tecNm)}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecNm}"/>
                        </f:facet>
                        <h:outputText value="#{tecnicoController.highlight(item.tecNm, 'tecNm}#{filterSearchController.removeAcentos(item.tecNm)')}" escape="false" />
                    </p:column>

                    <p:column filterBy="#{item.tecEmail}" sortBy="#{item.tecEmail}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecEmail}"/>
                        </f:facet>
                        <h:outputText value="#{tecnicoController.highlight(item.tecEmail, 'tecEmail')}" escape="false" />
                    </p:column>

                    <p:column style="width: 135px" filterBy="#{item.tecTelefone}" sortBy="#{item.tecTelefone}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecTelefone}">
                            </h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.tecTelefone}" converter="inputConverter"/>
                    </p:column>

                    <p:column style="width: 135px" filterBy="#{item.tecTelefone2}" sortBy="#{item.tecTelefone2}" filterMatchMode="contains">
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecTelefone2}">
                            </h:outputText>
                        </f:facet>
                        <h:outputText value="#{item.tecTelefone2}" converter="inputConverter"/>
                    </p:column>

                    <p:column sortBy="#{item.usinas}#{filterSearchController.removeAcentos(item.usinas)}" 
                              filterBy="#{item.usinas}#{filterSearchController.removeAcentos(item.usinas)}" filterMatchMode="contains" exportable="true" style="width: 300px; "> 
                        <f:facet name="header">
                            <h:outputText styleClass="cabecalhoNegrito" value="#{bundle.ListTecnicoTitle_tecUsina}">
                            </h:outputText>
                        </f:facet>   
                        <p:tooltip value="#{item.usinas}" for="columnUsina"/>
                        <h:outputText id="columnUsina" value="#{filterSearchController.cortarString(item.usinas)}"/>                                 
                    </p:column>


                    <p:column style="width: 3%;" exportable="false">
                        <div class="cabecalho">
                            <div class="imagem">
                                <p:commandLink ajax="true" update=":formList:displayView" oncomplete="tecnicoDialogView.show()" onerror="tecnicoDialogView.hide();" title="#{bundle.MsgVisualizar}" styleClass="ui-icon ui-icon-search">
                                    <f:setPropertyActionListener value="#{item}" 
                                                                 target="#{tecnicoController.selectedTecnico}" />
                                </p:commandLink>
                            </div>                 
                            <div class="titulo">
                                <p:commandLink ajax="false"  action="#{tecnicoController.prepareEdit}" rendered="#{!autenticadorController.loginVisualizador}" title="#{bundle.ListAreaEditLink}" styleClass="ui-icon ui-icon-pencil" >
                                    <f:setPropertyActionListener value="#{item}" 
                                                                 target="#{tecnicoController.selectedTecnico}" />
                                </p:commandLink>
                            </div>
                        </div>                     
                    </p:column>


                    <f:facet name="footer" class="test">        

                        <p:commandButton id="createCommand" rendered="#{!autenticadorController.loginVisualizador}" ajax="false" icon="#{bundle.icone_documento}" action="#{tecnicoController.prepareCreate}" value="#{bundle.ListTecnicoCreateLink}"/>
                        <p:commandButton id="viewCommand"  value="#{bundle.MsgVisualizar}" icon="#{bundle.icone_pesquisa}"  update=":formList:displayView" oncomplete="tecnicoDialogView.show()" actionListener="#{tecnicoController.prepareView}" />
                        <p:commandButton id="editCommand" ajax="false"  action="#{tecnicoController.prepareEdit}" value="#{bundle.ViewTecnicoEditLink}" rendered="#{!autenticadorController.loginVisualizador}" icon="#{bundle.icone_pencil}" />
                        <p:commandButton id="deleteCommand" ajax="false"  rendered="#{autenticadorController.loginAdmin}"  onclick="confirmationDestroy.show();" value="#{bundle.ViewTecnicoDestroyLink}" type="button" icon="#{bundle.icone_lixeira}" />

                        <p:commandButton id="excelExportAll" ajax="false" value="#{bundle.excelExportAll}" icon="#{bundle.icone_script}">
                            <p:dataExporter type="xls" target="tbl" fileName="#{bundle.excelExportAllFileName_tecnicos}" postProcessor="#{tecnicoController.postProcessorXLS}"/>
                        </p:commandButton>
                        <p:commandButton id="excelExportPagAtual" ajax="false" value="#{bundle.excelExportPagAtual}" icon="#{bundle.icone_calculadora}">
                            <p:dataExporter type="xls" target="tbl" fileName="#{bundle.excelExportPagAtualFileName_tecnicos}" pageOnly="true" postProcessor="#{tecnicoController.postProcessorXLS}"/>
                        </p:commandButton>
                    </f:facet>

                </p:dataTable>

                <p:confirmDialog id="confirmDestroy" message="#{bundle.MsgConfirmDestroy_message}" header="#{bundle.MsgConfirmDestroy_header}" severity="alert" widgetVar="confirmationDestroy">
                    <p:commandButton id="confirm" ajax="false" value="#{bundle.MsgDialog_confirmar}"  oncomplete="confirmationDestroy.hide(); #{tecnicoController.prepareList}" icon="#{bundle.icone_listar}" action="#{tecnicoController.destroy}" update="tbl"/>
                    <p:commandButton id="decline"  value="#{bundle.MsgDialog_cancelar}" update="messages" onclick="confirmationDestroy.hide();" type="button"/>

                </p:confirmDialog>

                <p:dialog modal="true" id="dialogView" header="#{bundle.TecnicoDialogView_header}" widgetVar="tecnicoDialogView" resizable="false" width="750" >

                    <h:panelGrid id="displayView" columns="2" cellpadding="4">                          

                        <h:outputText value="#{bundle.ViewTecnicoLabel_tecId}"/>
                        <h:outputText value="#{tecnicoController.selected.tecId}" title="#{bundle.ViewTecnicoTitle_tecId}"/>
                        <h:outputText value="#{bundle.ViewTecnicoLabel_tecNm}"/>
                        <h:outputText value="#{tecnicoController.selected.tecNm}" title="#{bundle.ViewTecnicoTitle_tecNm}"/>
                        <h:outputText value="#{bundle.ViewTecnicoLabel_tecEmail}"/>
                        <h:outputText value="#{tecnicoController.selected.tecEmail}" title="#{bundle.ViewTecnicoTitle_tecEmail}"/>
                        <h:outputText value="#{bundle.ViewTecnicoLabel_tecTelefone}"/>
                        <h:outputText value="#{tecnicoController.selected.tecTelefone}" converter="inputConverter" title="#{bundle.ViewTecnicoTitle_tecTelefone}"/> 
                        <h:outputText value="#{bundle.ViewTecnicoLabel_tecTelefone2}"/>
                        <h:outputText value="#{tecnicoController.selected.tecTelefone2}" converter="inputConverter" title="#{bundle.ViewTecnicoTitle_tecTelefone2}"/> 

                        <h:outputLabel value="#{bundle.EditTecnicoLabel_tecUsina}"/>                 
                        <p:dataList id="dataListUsinas" value="#{tecnicoController.selected.listaUsinas}" var="item" paginator="true" currentPageReportTemplate="Página {currentPage}/{totalPages} de {totalRecords} usinas(s)." paginatorPosition="bottom" rows="10" rowsPerPageTemplate="10" type="none" 
                                    paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}">
                            <h:outputText value="#{item.usiTpuId.tpuNm} #{item.usiNm} (#{item.orgao.orgNm})" style="margin-left:10px" />                        
                            <br />
                        </p:dataList>
                        <h:outputLabel value="#{bundle.createBy}" for="nomeCriador" rendered="#{tecnicoController.selected.historicoCriacao.nomeUsuario != null}"/>
                        <h:outputText id="nomeCriador" value="#{tecnicoController.selected.historicoCriacao.nomeUsuario}" rendered="#{tecnicoController.selected.historicoCriacao.nomeUsuario != null}"/>
                        <h:outputLabel value="#{bundle.createDate}" for="dataCriacao" rendered="#{tecnicoController.selected.historicoCriacao.dataHora != null}"/>
                        <h:outputText id="dataCriacao" value="#{tecnicoController.selected.historicoCriacao.dataHora}" rendered="#{tecnicoController.selected.historicoCriacao.dataHora != null}"/>     
                        <h:outputLabel value="#{bundle.updateBy}" for="nomeAlterador" rendered="#{tecnicoController.selected.historicoAlteracao.nomeUsuario != null}"/>
                        <h:outputText id="nomeAlterador" value="#{tecnicoController.selected.historicoAlteracao.nomeUsuario}" rendered="#{tecnicoController.selected.historicoAlteracao.nomeUsuario != null}"/>
                        <h:outputLabel value="#{bundle.updateDate}" for="dataAlteracao" rendered="#{tecnicoController.selected.historicoAlteracao.dataHora != null}"/>
                        <h:outputText id="dataAlteracao" value="#{tecnicoController.selected.historicoAlteracao.dataHora}" rendered="#{tecnicoController.selected.historicoAlteracao.dataHora != null}" /> 

                    </h:panelGrid>
                </p:dialog>
            </h:panelGroup>
        </ui:define>
    </ui:composition>

</html>
